//
//  LZVideoDetailRestaurantNameCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/3.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZVideoDetailRestaurantNameCell.h"
#import "GiftListLabel.h"
#import "HCSStarRatingView.h"
#import "Masonry.h"

@interface LZVideoDetailRestaurantNameCell()
@property (weak, nonatomic) IBOutlet GiftListLabel *restaurantNameLabel;
@property (weak, nonatomic) IBOutlet UIView *starBgView;
@property (strong, nonatomic) HCSStarRatingView *starRatingView;

@end

@implementation LZVideoDetailRestaurantNameCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.restaurantNameLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 110;
    
    self.starBgView.backgroundColor = [UIColor clearColor];
    
    [self configureLabel];
    [self configureStarRatingView];
    // Initialization code
}

- (void)loadRestaurantName:(NSString *)name StarLevel:(CGFloat)starLevel
{
    [self setRestaurantNameLabelLabelText:name];
    [self setStarViewWithLevel:starLevel];
}

- (void)setRestaurantNameLabelLabelText:(NSString *)text
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentLeft];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    self.restaurantNameLabel.attributedText = attStr;
}

- (void)setStarViewWithLevel:(CGFloat)index
{
    self.starRatingView.value = index;
}

#pragma mark -
#pragma mark configure label
- (void)configureLabel
{
    [self.restaurantNameLabel setVerticalAlignment:VerticalAlignmentTop];
}

- (void)configureStarRatingView {
    _starRatingView = [[HCSStarRatingView alloc]initWithFrame:CGRectZero];
    self.starRatingView.maximumValue = 5;
    self.starRatingView.minimumValue = 0;
    self.starRatingView.spacing = 2.5;
    self.starRatingView.tintColor = UIColorFromRGB(0xF08F4D, 1);
    self.starRatingView.userInteractionEnabled = NO;
    self.starRatingView.allowsHalfStars = YES;
    self.starRatingView.accurateHalfStars = YES;
    self.starRatingView.backgroundColor = [UIColor clearColor];
    [self.starBgView addSubview:self.starRatingView];
    
    [self.starRatingView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.starBgView);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
